package com.wfyvv.resteasy.api;

import com.wfyvv.resteasy.common.util.ResultUtils;
import com.wfyvv.resteasy.vo.TestVo;
import org.hibernate.validator.constraints.NotEmpty;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Path("/t")
@Produces(MediaType.APPLICATION_JSON)
public class TestApi {

    @GET
    @Path("/")
    public Map version() {
        return ResultUtils.success("REST API v1.0");
    }

    @GET
    @Path("/h")
    public Map hello(
            @NotEmpty(message = "name不能为空")
            @QueryParam("name") String name) {
        System.out.println("---test");
        return ResultUtils.success(name + " Hello World！");
    }

    @GET
    @Path("/o")
    public Map object() {
        TestVo testVo = new TestVo();
        testVo.setT("test vo");
        return ResultUtils.success(testVo);
    }

    @GET
    @Path("/l")
    public Map list() {
        TestVo testVo1 = new TestVo();
        testVo1.setT("test vo 1");
        TestVo testVo2 = new TestVo();
        testVo2.setT("test vo 2");
        List list = new ArrayList();
        list.add(testVo1);
        list.add(testVo2);
        return ResultUtils.success(list);
    }

    @GET
    @Path("test")
    @Produces("text/html;charset=utf-8")
    public Response getExampleTxt() {
        return Response.status(500).entity("<h2 style='color:red'>中文乱码</h2>").build();
    }

}
